<template>
  <div class="baobei">
    <el-dialog
      title="批示意见/办理提示"
      :visible.sync="dialogVisible"
      width="60%">
      <notice :noticePersonId="noticePersonId" :step="selStep"></notice>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="录入电话记录表"
      :visible.sync="telRecordVisible"
      width="80%" :close-on-click-modal="false" :close-on-press-escape="false">
        <el-form
          :model="telRecordForm"
          ref="telRecordForm"
          label-width="150px"
          label-position="right"
          :rules="telRecordFormRules"
          :inline="true"
          >
          <el-form-item label="电话时间" prop="telTime">
            <el-date-picker
              v-model="telRecordForm.telTime"
              type="datetime"
              placeholder="选择日期时间"
              format="yyyy-MM-dd HH:mm"
              value-format="yyyy-MM-dd HH:mm">
            </el-date-picker>
          </el-form-item>
          <div style="clear:both"></div>
          <el-form-item label="来电单位" prop="telComp1">
            <el-input v-model="telRecordForm.telComp1"></el-input>
          </el-form-item>
          <el-form-item label="来电人及职务" prop="telPerson1">
            <el-input v-model="telRecordForm.telPerson1"></el-input>
          </el-form-item>
          <el-form-item label="电话号码" prop="telNum1">
            <el-input v-model="telRecordForm.telNum1"></el-input>
          </el-form-item>
          <div style="clear:both"></div>
          <el-form-item label="接电单位" prop="telComp2">
            <el-input v-model="telRecordForm.telComp2"></el-input>
          </el-form-item>
          <el-form-item label="接听人及职务" prop="telPerson2">
            <el-input v-model="telRecordForm.telPerson2"></el-input>
          </el-form-item>
          <el-form-item label="电话号码" prop="telNum2">
            <el-input v-model="telRecordForm.telNum2"></el-input>
          </el-form-item>
          <div style="clear:both"></div>
          <el-form-item label="来电内容" prop="content">
            <el-input type="textarea" v-model="telRecordForm.content" style="width:935px"></el-input>
          </el-form-item>
          <div style="clear:both"></div>
          <el-form-item label="领导批注" prop="leaderOpinion">
            <el-input type="textarea" v-model="telRecordForm.leaderOpinion" style="width:935px"></el-input>
          </el-form-item>
          <div style="clear:both"></div>
          <el-form-item label="办理情况" prop="handlingSituation">
            <el-input type="textarea" v-model="telRecordForm.handlingSituation" style="width:935px"></el-input>
          </el-form-item>
          <div style="clear:both"></div>
          <el-form-item label="备注" prop="comment">
            <el-input type="textarea" v-model="telRecordForm.comment" style="width:935px"></el-input>
          </el-form-item>
          <div style="clear:both"></div>
          <el-form-item>
            <el-button type="success" style="margin-left:150px;" @click="finishBL">办理完成</el-button>
          </el-form-item>
        </el-form>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/selection' }">干部选任</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/selection/necessary/baobei' }">报中组部备案</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxnoborder">
      <div :style="'height:'+tableHeight+'px'">
        <el-scrollbar style="height: calc(100% + 16px);">
          <el-tabs v-model="activeName" type="card" @tab-click="tabsClick" style="margin:15px">
            <el-tab-pane label="待办理" name="first">
              <span slot="label" v-if="countnum1>0" class="pointtab"><el-badge :value="countnum1" class="item">待办理</el-badge></span>
                <el-table
                  v-loading="listloading1"
                  border
                  size="small"
                  :data="tableData"
                  tooltip-effect="dark"
                  style="width: 100%"
                  @selection-change="handleSelectionChange">
                  <el-table-column
                    type="selection"
                    width="55">
                  </el-table-column>
                  <el-table-column
                    label="序号"
                    type="index"
                    width="50">
                  </el-table-column>
                  <el-table-column
                    prop="realName"
                    label="姓名"
                    width="100"
                    show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column
                    prop="candidateUnit"
                    label="目前单位"
                    show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column
                    prop="currentJob"
                    label="目前职务"
                    width="200"
                    show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column
                    prop="currentLevel"
                    label="目前职级"
                    width="150"
                    show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column
                    prop="unitName"
                    label="选任岗位单位"
                    show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column
                    prop="jobName"
                    width="200"
                    label="选任岗位职务"
                    show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column
                    prop="jobLevel"
                    label="选任岗位职级"
                    width="150"
                    show-overflow-tooltip>
                  </el-table-column>
                  <el-table-column
                    label="办理提示、批示意见"
                    width="150">
                    <template slot-scope="scope">
                      <el-popover placement="bottom" width="600" trigger="hover">
                        <notice :noticePersonId="scope.row.personId" step="8"></notice>
                        <el-button size="small" slot="reference" type="primary" @click="showNotice(scope.row.personId)">查看详情</el-button>
                      </el-popover>
                      <!-- <el-button @click="showNotice(scope.row.personId)" type="primary" size="small">查看详情</el-button> -->
                    </template>
                  </el-table-column>
                </el-table>
                <el-button class="marginT10" type="primary" @click="baobuClick" :loading="submitloading">报中组部备案</el-button>
            </el-tab-pane>
            <el-tab-pane label="办理中" name="second">
              <span slot="label" v-if="countnum2>0" class="pointtab"><el-badge :value="countnum2" class="item">办理中</el-badge></span>
              <el-table
                v-loading="listloading2"
                border
                size="small"
                ref="multipleTable"
                :data="tableData2"
                tooltip-effect="dark"
                style="width: 100%">
                <el-table-column
                  label="序号"
                  type="index"
                  width="50">
                </el-table-column>
                <el-table-column
                  prop="names"
                  label="人选"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  label="操作"
                  width="580">
                  <template slot-scope="scope">
                    <el-button @click="telRecord(scope.row)" type="success">录入电话记录表</el-button>
                    <el-button @click="exportbabg(scope.row.id)"  type="primary">导出备案报告模板</el-button>
                    <el-button @click="delBL(scope.row)" type="danger" class="marginL8">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
          </el-tabs>
        </el-scrollbar>
      </div>
    </section>
  </div>
</template>

<script>
import notice from '../common/Notice'
export default {
  name: 'baobei',
  components: {
    notice
  },
  data () {
    return {
      telRecordForm: {
        telTime: '',
        telComp1: '',
        telPerson1: '',
        telNum1: '',
        telComp2: '',
        telPerson2: '',
        telNum2: '',
        content: '你单位报来的《中共自然资源部党组关于×××等×名同志职务任免（任职）备案的报告》（自然资党任[××××] ×号）收悉，经审核，没有不同意见（答复如下: ×××××× )，请按规定程序办理。',
        leaderOpinion: '',
        handlingSituation: '',
        comment: ''
      },
      telRecordFormRules: {
        telTime: [{ required: true, message: '请选择电话时间', trigger: 'blur' }],
        telComp1: [{ required: true, message: '请填写来电单位', trigger: 'blur' }],
        telPerson1: [{ required: true, message: '请填写来电人及职务', trigger: 'blur' }],
        telNum1: [{ required: true, message: '请填写电话号码', trigger: 'blur' }],
        telComp2: [{ required: true, message: '请填写接电单位', trigger: 'blur' }],
        telPerson2: [{ required: true, message: '请填接听人姓名及职务', trigger: 'blur' }],
        telNum2: [{ required: true, message: '请填写电话号码', trigger: 'blur' }],
        content: [{ required: true, message: '请填写来电内容', trigger: 'blur' }],
        leaderOpinion: [{ required: true, message: '请填写领导批注', trigger: 'blur' }],
        handlingSituation: [{ required: true, message: '请填写办理情况', trigger: 'blur' }]
      },
      putOnRecordBatchId: '',
      telRecordVisible: false,
      countnum1: 0,
      countnum2: 0,
      tableHeight: 100,
      activeName: 'first',
      listloading1: false,
      listloading2: false,
      submitloading: false,
      submitloading2: false,
      tableData: [],
      tableData2: [],
      baobeiPersons: [], // 代办理表格 table select change
      files: [],
      fileList: [], // 办理中 上传附件
      selectData: {
        hjData: [
        ],
        szData: [
        ],
        cnData: [
        ],
        yyData: []
      },
      selectPerson: [], // 待批示
      selectPerson2: [], // 已批示
      selApi: 'api/selection/putonrecord/submitApprove',
      selStep: 7,
      noticePersonId: '', // notice persion id
      dialogVisible: false // 已批示
    }
  },
  methods: {
    exportbabg (id) {
      let url = this.$http.defaults.selectionAPI + 'api/selection/document/exportZzbba?batchId=' + id
      // console.log(url)
      this.$http.get(url).then(res => {
        if (res.data.success === true) {
          this.download(res.data.result)
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    exportTelRecord (id) {
      let url = this.$http.defaults.selectionAPI + 'api/selection/document/exportDhjlb?batchId=' + id
      // console.log(url)
      this.$http.get(url).then(res => {
        if (res.data.success === true) {
          this.download(res.data.result)
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    // window.open(this.$http.defaults.baseURL + this.$http.defaults.selectionAPI + 'api/selection/document/exportDhjlb?batchId=' + id)
    },
    download (fileid) {
      var downloadElement = document.createElement('a')
      downloadElement.href = this.$http.defaults.baseURL + this.$http.defaults.selectionAPI + 'api/gen/file/download?id=' + fileid
      document.body.appendChild(downloadElement)
      downloadElement.click() // 点击下载
      document.body.removeChild(downloadElement) // 下载完成移除元素
    },
    telRecord (item) {
      this.putOnRecordBatchId = item.id
      this.telRecordVisible = true
      // this.$refs['telRecordForm'].resetFields()
      console.log(item.names)
      console.log(item.names.split(' ')[0] + '等')
      console.log(item.names.split(' ').length + '名')
      this.telRecordForm.content = '你单位报来的《中共自然资源部党组关于 ' + item.names.split(' ')[0] + ' 等 ' + item.names.split(' ').length + ' 名' + '同志职务任免（任职）备案的报告》（自然资党任[××××] ×号）收悉，经审核，没有不同意见（答复如下: ×××××× )，请按规定程序办理。'
    },
    showNotice (id) {
      this.noticePersonId = id
      this.dialogVisible = true
    },
    getNum () {
      let url = this.$http.defaults.selectionAPI + 'api/selection/statnum/putonrecord/getStatNum'
      // console.log(url)
      this.$http.get(url).then(res => {
        if (res.data.success === true) {
          this.countnum1 = res.data.result.countnum4 // 处内人员的countnum1对应处长的countnum4
          this.countnum2 = res.data.result.countnum2
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    saveComplete () {
      if (this.selectPerson2.length === 0) {
        this.$message({
          message: '请至少选择一个人选',
          type: 'error'
        })
        return
      }
      this.submitloading2 = true
      let url = this.$http.defaults.selectionAPI + this.selApi
      let arr = []
      for (let i of this.selectPerson2) {
        if (i.passed !== 1 && i.passed !== 0) {
          this.$message({
            message: '请选择每一位勾选人选是否同意',
            type: 'warning'
          })
          return
        } else {
          arr.push({
            id: i.personId,
            passed: i.passed
          })
        }
      }
      this.$http.post(url, {
        receiveUserId: -1,
        persons: arr,
        step: 7
      }).then(res => {
        this.submitloading2 = false
        if (res.data.success === true) {
          this.$message({
            message: '办理完成',
            type: 'success'
          })
          this.getList4()
        }
      })
    },
    tabsClick (tab) {
    // console.log(tab)
      if (tab.name === 'first') {
        console.log('first in')
        this.getList()
      } else if (tab.name === 'second') {
        this.getList2()
      }
    },
    getList2 () {
      this.getNum()
      this.listloading2 = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/putonrecord/getProcessingBatchInfo'
      // console.log(url)
      this.$http.get(url, {}).then(res => {
        this.listloading2 = false
        console.log('get list22 succ:', res)
        if (res.data.success === true) {
          let rs = res.data.result
          let arr = []
          for (let i of rs) {
            let brr = []
            for (let j of i.persons) {
              brr.push(j.realName)
            }
            arr.push({
              id: i.id,
              names: brr.join(' '),
              files: i.files,
              persons: i.persons
            })
          }
          this.tableData2 = arr
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    getList () {
      this.getNum()
      this.listloading1 = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/putonrecord/getApprove'
      // console.log(url)
      this.$http.get(url, {}).then(res => {
        this.listloading1 = false
        console.log('get list44 succ:', res)
        if (res.data.success === true) {
          this.tableData = res.data.result
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    handleSelectionChange (val) { // 报部 待办理
      console.log('tabledata val:', val)
      this.baobeiPersons = [...val]
    },
    baobuClick () { // 报中组部 按钮
      this.submitloading = true
      console.log('click baobu')
      let url = this.$http.defaults.selectionAPI + 'api/selection/putonrecord/saveBatchByPersons'
      // console.log(url)
      // 获取报备persons
      let arr = []
      for (let i of this.baobeiPersons) {
        arr.push(i.personId)
      }
      this.$http.post(url, {
        personIds: arr
      }).then(res => {
        this.submitloading = false
        console.log('报中组部备案 succ res:', res)
        if (res.data.success === true) {
          this.$message({
            message: '报中组部备案成功',
            type: 'success'
          })
          this.getList()
        }
      })
    },
    handleUploadSucc (response, file, fileList) { // 带上会审议 录入领导批示 附件
      console.log(response)
      if (response.success) {
        this.files.push(response.result[0])
        this.$message({
          message: '上传成功！' + response.message,
          type: 'success'
        })
      } else {
        this.$message({
          message: '上传失败:' + response.message,
          type: 'error'
        })
      }
    },
    beforeRemove (file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`)
    },
    handleRemove (file, fileList) {
      console.log(file, fileList)
      let fid = file.response.result[0].id
      let url = this.$http.defaults.selectionAPI + 'api/gen/file/remove'
      this.$http.get(url, {
        params: {
          id: fid
        }
      }).then(res => {
        console.log('删除成功:', res)
        if (res.data.success === true) {
          let index = this.files.indexOf(fid)
          if (index !== -1) {
            this.files.splice(index, 1)
            this.$message({
              message: '删除成功！',
              type: 'success'
            })
          }
        }
      })
    },
    uploadError (err) {
      console.log(err)
      this.$message({
        message: '上传失败:' + err,
        type: 'error'
      })
    },
    finishBL (item) { // 办理中 完成
      this.$refs['telRecordForm'].validate((valid) => {
        if (valid) {
          let url = this.$http.defaults.selectionAPI + 'api/selection/putonrecord/updateBatchComplete'
          this.$http.post(url, {
            putOnRecordBatchId: this.putOnRecordBatchId,
            telephoneRecord: JSON.stringify(this.telRecordForm)
          }).then(res => {
            if (res.data.success === true) {
              this.$message({
                message: '已完成',
                type: 'success'
              })
              this.telRecordVisible = false
              this.getList2()
            }
          })
        }
      })
    },
    delBL (item) { // 办理中 删除
      console.log('del', item)
      this.$confirm('是否删除待上会审议批次', '操作确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let url = this.$http.defaults.selectionAPI + 'api/selection/putonrecord/removeBatch'
        this.$http.get(url, {
          params: {
            putOnRecordBatchId: item.id
          }
        }).then(res => {
          console.log('删除办理批次res:', res)
          if (res.data.success === true) {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
            this.getList2()
          }
        })
      }).catch(() => {
        console.log('取消删除')
      })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 165
      })
    }
  },
  mounted () {
    // let params = this.$route.params
    // console.log('讨论决定详情params:', params)
    // 代办理列表
    this.getList()
    // resize
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>

<style>
.baobei .el-table--border td, .el-table--border th, .el-table__body-wrapper .el-table--border.is-scrolling-left~.el-table__fixed{
  border-bottom:1px solid #95B8E7;
}
.baobei .el-table td, .el-table th.is-leaf{
  border-right:1px solid #95B8E7;
}
.baobei .wboxnoborder .el-table{
  border: #95B8E7 solid 1px;
}
.baobei .wboxnoborder .el-table th{
  font-weight: normal;
  background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  text-align: center;
  border-right: #95B8E7 solid 1px;
  border-bottom: #95B8E7 solid 1px;
  min-height: 30px;
  line-height:30px;
}
.baobei .wboxnoborder .el-table td, .el-table th{
  padding:0;
  font-size:var(--size14) !important;
  line-height: 20px;
  font-family: '宋体';
  text-align: center;
}
.baobei .el-table__row{
  height: 50px;
}
</style>
<style scoped>
.baobei {
  width: 100%;
}
.baobei .wboxnoborder {
  padding: 0;
  width: 100%;
  background-color: #fff;
  margin: 0 10px;
  overflow: hidden;
}
</style>
